package cn.yunhe.songshan.ssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.yunhe.songshan.ssm.model.User;
import cn.yunhe.songshan.ssm.service.IUserService;

@Controller
public class UserController {
	
	@Autowired
	private IUserService userService;
	
	@RequestMapping("/user")
	public String getUser(int a){

		if(a==5){
			throw new NullPointerException();
		}
		return "index";
	}
	
	@RequestMapping(value="/user",method=RequestMethod.POST)
	public String addUser(User user) throws Exception{

//		try {
//			new UserServiceImpl().userAdd(user);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
		System.out.println("接受参数为"+user);
		int rownum = 0;
		
		rownum = userService.userAdd(user);
		
		if(rownum==1){
			throw new Exception();
		}
		
		return "index";
	}
	
	
}
